package com.leanyuan.Infor.controller;



import com.leanyuan.Infor.api.Result;
import com.leanyuan.Infor.config.SecurityUtils;
import com.leanyuan.Infor.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

//@CrossOrigin(origins = "http://localhost:8080",maxAge = 3600,)
@RestController
public class LoginController {

    @Autowired
    AuthenticationManager authenticationManager;

    @PostMapping(value = "/login")
    public Result<Object> login(@RequestBody Map<String,String> params)  {
        System.out.println(params);
        User userInfo = SecurityUtils.login(params.get("username"), params.get("password"), authenticationManager);
        System.out.println(userInfo);
        return Result.ok(userInfo);
    }


    @GetMapping(value = "/home")
    public Result<Object> home()  {
        System.out.println("..");return Result.ok("aa");
    }

}
